
var app = getApp()
var Bmob = require('../../utils/Bmob-2.2.0.min.js');
var WxParse = require('../../utils/wxParse/wxParse.js');
Page({
  data: {
    thingsId: '',
    thingsInfo: {},
    defaultPhoto: '',
    goodsList: [],
    appointmentList: [],
    tostoreList: [],
    has_goods_type: [],
    onBusiness: true,
    
  },
  form: '',
  page: 1,
  onLoad: function (options) {
    var thingsId = options.detail,
      that = this;
     // defaultPhoto = app.getDefaultPhoto();
    
    this.setData({
      thingsId: thingsId
    
    })
    that.getthingsInfo(thingsId);
    /*
    app.sendRequest({
      url: '/index.php?r=AppShop/GetAppShopByPage',
      data: {
        sub_shop_app_id: franchiseeId
      },
      success: function(res){

        var data = {},
            has_goods_type = res.data[0].has_goods_type;

        data.franchiseeInfo = res.data[0];
        data.franchiseeInfo.business_time_str = data.franchiseeInfo.business_time_str.replace(/\,/g , '\n');

        data.onBusiness = res.data[0].is_open == 0 ? false : true;
        if(has_goods_type.length){
          data.has_goods_type = has_goods_type;
          for (var i = 0; i < has_goods_type.length;i++){
           
            switch (+has_goods_type[i]) {
              case 0:
                that.getGoodsList('goods');
                break;
              case 1:
                that.getGoodsList('appointment');
                break;
              case 3:
                that.getGoodsList('tostore');
                break;
            }
          }
          
        }
        that.setData(data);
      }
    })*/
  },
  // onReachBottom: function(){
  //   if(this.data.has_goods_type.length){
  //     this.getGoodsList();
  //   }
  // },
  
  getthingsInfo: function (id) {
    var that = this;
    
    var things =  Bmob.Query("things");
    things.get(id).then(res => {
      WxParse.wxParse('content', 'html', res.things_detail, that);
      that.setData({

        thingsInfo: res

      })})
 
  },


  
  turnToGoodsMore: function (e) {
    let form = e.currentTarget.dataset.form,
      typeData = e.currentTarget.dataset.type;
    app.turnToPage('/pages/goodsMore/goodsMore?detail=' + form + '&franchisee=' + this.data.franchiseeId + '&type=' + typeData);
  },

  
  franchiseeCoverOnload: function (e) {
    var originalWidth = e.detail.width,
      originalHeight = e.detail.height;

    //获取图片的原始长宽
    var windowWidth = 0;
    var imageWidth = 0, imageHeight = 0;

    var res = app.getSystemInfoData();

    windowWidth = res.windowWidth;
    imageWidth = windowWidth;
    imageHeight = imageWidth * originalHeight / originalWidth;
    this.setData({
      franchiseeCoverWidth: imageWidth,
      franchiseeCoverHeight: imageHeight > imageWidth ? imageWidth : imageHeight
    })
  },
  makePhoneCall: function (e) {
    var phone_num = e.currentTarget.dataset.phoneNum;
   
    app.makePhoneCall(phone_num);
  },
  clickFranchiseeAddress: function (e) {
    var dataset = e.currentTarget.dataset,
      eventParams = '';
console.log(dataset);
    app.openLocation({
      latitude: +dataset.lat,
      longitude: +dataset.lng,
      scale: 20
    })
  },
  onShareAppMessage: function () {

  }
})
